const chars = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '拾']
const units = ['', '拾', '佰', '仟']
const bigUnits = ['', '万', '亿']
const pointE = ['角', '分']


export function transitionF(str: string) {
    const strs = str
        .replace(/(?=(\d{4})+$)/g, ',')
        .split(',')
        .filter(Boolean)


    function _transform(numStr: string) {
        let result = ''
        for (let i = 0; i < numStr.length; i++) {
            const dight = +numStr[i]
            const u = units[numStr.length - 1 - i]
            const c = chars[dight]
            if (dight === 0) {
                if (result[result.length - 1] !== chars[0]) {
                    result += c
                }
            } else {
                result += c + u
            }
        }

        if (result[result.length - 1] === chars[0]) {
            result = result.slice(0, -1)
        }
        return result
    }
    _transform('3000')
    let res = ''
    for (let i = 0; i < strs.length; i++) {
        const c = _transform(strs[i])
        const u = c ? bigUnits[strs.length - 1 - i] : ""
        res += c + u
    }

    return res
}

export function transitionE(str: string) {
    let result = ''
    for (let i = 0; i < str.length; i++) {
        if (+str[i] !== 0) {
            result += chars[+str[i]] + pointE[i]
        }
    }
    return result
}